﻿using System.Web.Mvc;

namespace MyLab.Mvc
{
    public class MainsiteMenuItem : MenuItem
    {
        public MainsiteMenuItem(string text, string actionName, string controllerName)
            : this(text, actionName, controllerName, false)
        { }

        public MainsiteMenuItem(string text, string actionName, string controllerName, bool isCurrentItem)
        {
            Text = text;
            ActionName = actionName;
            ControllerName = controllerName;
            IsCurrent = isCurrentItem;
        }

        public override string RenderItem(string currentItemCssClass)
        {
            TagBuilder li = new TagBuilder("li");
            TagBuilder a = new TagBuilder("a");

            if (IsCurrent)
                li.AddCssClass(currentItemCssClass);
            a.Attributes.Add("href", string.Format("/{0}/{1}", ControllerName, ActionName));
            a.SetInnerText(Text);

            li.InnerHtml = a.ToString();

            return li.ToString();
        }
    }
}
